package com.cacshanghai.cac_oa_client.ui;

import android.os.Bundle;
import android.widget.GridView;
import android.widget.TextView;

import com.cacshanghai.cac_oa_client.R;
import com.cacshanghai.cac_oa_client.adapter.AttendanceCalendarAdapter;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by geyh on 2016/5/27.
 * 考勤
 */
public class AttendanceActivity extends BaseActivity {

    private String currentDate = "";
    private int year_c = 0;
    private int month_c = 0;
    private int day_c = 0;
    private int jumpMonth = 0; // 每次滑动，增加或减去一个月,默认为0（即显示当前月）
    private int jumpYear = 0; // 滑动跨越一年，则增加或者减去一年,默认为0(即当前年)
    private TextView currentMonth;
    private GridView gv_calendar;
    private AttendanceCalendarAdapter calendarAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_attendance);
        setTitle(getString(R.string.attendance_manager) + "(葛仪豪)");
        setBack();
        initCalendar();
    }

    private void initCalendar() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");
        currentDate = sdf.format(date); // 当期日期
        year_c = Integer.parseInt(currentDate.split("-")[0]);
        month_c = Integer.parseInt(currentDate.split("-")[1]);
        day_c = Integer.parseInt(currentDate.split("-")[2]);

        currentMonth = (TextView) findViewById(R.id.currentMonth);
        gv_calendar = (GridView) findViewById(R.id.gv_calendar);
        calendarAdapter = new AttendanceCalendarAdapter(this, getResources(), jumpMonth, jumpYear, year_c, month_c, day_c);
        gv_calendar.setAdapter(calendarAdapter);
        changeCalendarTitle();
    }

    private void changeCalendarTitle() {
        StringBuffer textDate = new StringBuffer();
        textDate.append(calendarAdapter.getShowYear()).append("年").append(calendarAdapter.getShowMonth()).append("月").append("\t");
        currentMonth.setText(textDate);
    }
}
